<?php
if (!defined('ZAZA')) exit('No direct script access allowed');
/**
 * @copyright     ZaZa Group
 * @author        Sir Doan
 */

class Register extends Form
{
    function __construct()
    {                          
        Form::__construct('RegisterForm'); 
        tpl()->layout = 'api_login';  
        if(Obj()->get('openid_ext1_value_email') != '')
        {
            $user = db()->selectOne('manager', '*', 'email = "'. Obj()->get('openid_ext1_value_email') .'" AND status = 1');
            if($user){ 
                $_SESSION[NAME_SESSION_USER] = $user; 
                echo '<script type = "text/javascript"> self.close();</script>'; 
                //Url::redirect(array('gameid'=>2), 'newthread');
            }   
        }
    }  
    // Method Submit
    function is_submit()
    {
        $userid = db()->insert('manager', array('fullname' => Obj()->get('fullname'), 'email' => Obj()->get('email'), 'gold' => 20000));
        if($userid)
        {
            $user = db()->selectOne('manager', '*', 'email = "'. Obj()->get('openid_ext1_value_email') .'" AND status = 1');
            if($user){ 
                $_SESSION[NAME_SESSION_USER] = $user; 
                echo '<script type = "text/javascript"> self.close();</script>'; 
                if(Obj()->get('threadid', 'int', 0) != 0)
                    $params = array('threadid' => Obj()->get('threadid', 'int', 0));
                else
                    $params = null;
                Url::redirect($params, Obj()->get('func'));
            }  
        }
    }
    // Method Draw
    function draw()
    {              
        tpl()->assign('form', array('begin' => $this->begin(), 'end' => $this->end()));
        return tpl()->display('register'); 
    }   
}  
?>
